﻿Public Class LABGROUP
    Dim connect As CONDB = CONDB.NewConnection()
    Dim PROVIDER_Check As New PROVIDERSCLASS

    Private Sub TextBoxX1_KeyPress(sender As Object, e As KeyPressEventArgs) Handles DIS_ORDERTxt.KeyPress
        If Not IsNumeric(e.KeyChar) And Not e.KeyChar = ChrW(Keys.Back) Then
            e.Handled = True
        End If
    End Sub

    Private Sub LABGROUP_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Dim objSelectDataLab_group As New LABGROUP
        Dim lab_groupData As DataTable
        lab_groupData = connect.GetTable(objSelectDataLab_group.selectLabgroup_)
        'masgrpdrgData = connectlocal.GetTable(objSelectDataMasgrpdrg.selectMasgrpdrg_)
        LABGROUPGrid.PrimaryGrid.DataSource = lab_groupData

        DesignForm(Me)
        DesignGrid(LABGROUPGrid)

        PROVIDER_Check.GETHOSEM(CInt(main.txtUserRequest.Text.Trim), Convert.ToString(Me.Tag))
    End Sub

    Private Sub LABGROUPGrid_CellClick(sender As Object, e As DevComponents.DotNetBar.SuperGrid.GridCellClickEventArgs) Handles LABGROUPGrid.CellClick
        Dim grid As DevComponents.DotNetBar.SuperGrid.GridRow
        grid = e.GridPanel.ActiveRow
        'f.TXT_CID.Text = grid.Cells.Item(2).Value
        LAB_GROUP_CODETxt.Text = CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("รหัสกลุ่ม lab").Value()
        LAB_GROUP_NAMETxt.Text = CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("ชื่อกลุ่ม lab").Value()
        If CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("ชื่อย่อกลุ่ม lab").Value().ToString.Length > 0 Then
            LAB_GROUP_SHORT_NAMETxt.Text = CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("ชื่อย่อกลุ่ม lab").Value()
        Else
            LAB_GROUP_SHORT_NAMETxt.Text = ""
        End If

        DIS_ORDERTxt.Text = CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("ลำดับ").Value()

        If CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("สถานะการเปิดใช้งาน").Value() = True Then
            lab_groupStatusChk.Checked = True
        Else
            lab_groupStatusChk.Checked = False
        End If

        Dim objChkboxUpdate As New CLICKGRIDCHECKBOX
        objChkboxUpdate.clickChkboxUpdate("lab_group", CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("สถานะการเปิดใช้งาน").Value(), "STATUS", "LAB_GROUP_CODE", LAB_GROUP_CODETxt.Text)
    End Sub

    Private Sub moveOrderUPBtn_Click(sender As Object, e As EventArgs) Handles moveOrderUPBtn.Click
        If main.PROVIDERPOLICIES.checklogin_user_ = True Then
            If PROVIDER_Check.PUPD_ = True Then
                Dim objMoveOrder As New LABGROUP
                objMoveOrder.moveOrder("up", DIS_ORDERTxt.Text)

                Dim objSelectDataLab_group As New LABGROUP
                Dim lab_groupData As DataTable
                lab_groupData = connect.GetTable(objSelectDataLab_group.selectLabgroup_)
                'masgrpdrgData = connectlocal.GetTable(objSelectDataMasgrpdrg.selectMasgrpdrg_)
                LABGROUPGrid.PrimaryGrid.DataSource = lab_groupData
            Else
                MsgBox(PROVIDER_Check.PUPDMSG_)
            End If
        Else
            TOASTCLASS.gloadToastMSG(Me, main.PROVIDERPOLICIES.LOGINUSERMSG_)
            main.txtUserRequest.Focus()
        End If
    End Sub

    Private Sub moveOrderDownBtn_Click(sender As Object, e As EventArgs) Handles moveOrderDownBtn.Click
        If main.PROVIDERPOLICIES.checklogin_user_ = True Then
            If PROVIDER_Check.PUPD_ = True Then
                Dim objMoveOrder As New LABGROUP
                objMoveOrder.moveOrder("down", DIS_ORDERTxt.Text)

                Dim objSelectDataLab_group As New LABGROUP
                Dim lab_groupData As DataTable
                lab_groupData = connect.GetTable(objSelectDataLab_group.selectLabgroup_)
                'masgrpdrgData = connectlocal.GetTable(objSelectDataMasgrpdrg.selectMasgrpdrg_)
                LABGROUPGrid.PrimaryGrid.DataSource = lab_groupData
            Else
                MsgBox(PROVIDER_Check.PUPDMSG_)
            End If
        Else
            TOASTCLASS.gloadToastMSG(Me, main.PROVIDERPOLICIES.LOGINUSERMSG_)
            main.txtUserRequest.Focus()
        End If
    End Sub

    Private Sub addLabgroup_Click(sender As Object, e As EventArgs) Handles addLabgroup.Click
        If main.PROVIDERPOLICIES.checklogin_user_ = True Then
            If PROVIDER_Check.PADD_ = True Then
                If LAB_GROUP_NAMETxt.Text.ToString.Length > 0 And LAB_GROUP_SHORT_NAMETxt.Text.ToString.Length > 0 Then
                    Dim objInsertData As New LABGROUP
                    objInsertData.LAB_GROUP_NAME_ = LAB_GROUP_NAMETxt.Text
                    objInsertData.LAB_GROUP_SHORT_NAME_ = LAB_GROUP_SHORT_NAMETxt.Text
                    objInsertData.STATUS_ = lab_groupStatusChk.Checked
                    objInsertData.insertLab_groupData()

                    Dim objSelectDataLab_group As New LABGROUP
                    Dim lab_groupData As DataTable
                    lab_groupData = connect.GetTable(objSelectDataLab_group.selectLabgroup_)
                    'masgrpdrgData = connectlocal.GetTable(objSelectDataMasgrpdrg.selectMasgrpdrg_)
                    LABGROUPGrid.PrimaryGrid.DataSource = lab_groupData

                    LAB_GROUP_CODETxt.Text = ""
                    LAB_GROUP_NAMETxt.Text = ""
                    LAB_GROUP_SHORT_NAMETxt.Text = ""
                    DIS_ORDERTxt.Text = ""
                    lab_groupStatusChk.Checked = False
                Else
                    MsgBox("โปรดระบุข้อมูลให้ครบถ้วน")
                End If
            Else
                MsgBox(PROVIDER_Check.PADDMSG_)
            End If
        Else
            TOASTCLASS.gloadToastMSG(Me, main.PROVIDERPOLICIES.LOGINUSERMSG_)
            main.txtUserRequest.Focus()
        End If
    End Sub

    Private Sub editLabgroup_Click(sender As Object, e As EventArgs) Handles editLabgroup.Click
        If main.PROVIDERPOLICIES.checklogin_user_ = True Then
            If PROVIDER_Check.PUPD_ = True Then
                If LAB_GROUP_CODETxt.Text.ToString.Length > 0 And LAB_GROUP_NAMETxt.Text.ToString.Length > 0 And LAB_GROUP_SHORT_NAMETxt.Text.ToString.Length > 0 And DIS_ORDERTxt.Text.ToString.Length > 0 Then
                    Dim editStat As Integer
                    editStat = MsgBox("ท่านต้องการแก้ไขข้อมูลกลุ่ม lab ดังกล่าวใช่หรือไม่", MsgBoxStyle.OkCancel)

                    If editStat = 1 Then
                        Dim objEditData As New LABGROUP
                        objEditData.LAB_GROUP_CODE_ = LAB_GROUP_CODETxt.Text
                        objEditData.LAB_GROUP_NAME_ = LAB_GROUP_NAMETxt.Text
                        objEditData.LAB_GROUP_SHORT_NAME_ = LAB_GROUP_SHORT_NAMETxt.Text
                        objEditData.DIS_ORDER_ = DIS_ORDERTxt.Text
                        objEditData.STATUS_ = lab_groupStatusChk.Checked
                        objEditData.editLab_groupData()

                        Dim objSelectDataLab_group As New LABGROUP
                        Dim lab_groupData As DataTable
                        lab_groupData = connect.GetTable(objSelectDataLab_group.selectLabgroup_)
                        'masgrpdrgData = connectlocal.GetTable(objSelectDataMasgrpdrg.selectMasgrpdrg_)
                        LABGROUPGrid.PrimaryGrid.DataSource = lab_groupData

                        LAB_GROUP_CODETxt.Text = ""
                        LAB_GROUP_NAMETxt.Text = ""
                        LAB_GROUP_SHORT_NAMETxt.Text = ""
                        DIS_ORDERTxt.Text = ""
                        lab_groupStatusChk.Checked = False
                    End If
                Else
                    MsgBox("โปรดระบุข้อมูลให้ครบถ้วน")
                End If
            Else
                MsgBox(PROVIDER_Check.PUPDMSG_)
            End If
        Else
            TOASTCLASS.gloadToastMSG(Me, main.PROVIDERPOLICIES.LOGINUSERMSG_)
            main.txtUserRequest.Focus()
        End If
    End Sub

    Private Sub importExel_Click(sender As Object, e As EventArgs) Handles importExel.Click
        Dim nextform As New IMPORTEXCEL("labgroup")
        nextform.ShowDialog()
    End Sub

    Private Sub exportExcel_Click(sender As Object, e As EventArgs) Handles exportExcel.Click
        Dim nextform As New IMPORTEXCEL("labgroup")
        nextform.ShowDialog()
    End Sub
End Class